package com.qf.spring2202.aop.postprocessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * bean 后置处理器
 * 允许我们参与到sprig ioc容器创建 bean的过程中去
 * 参与的时机：
 * (1) 在调用bean 对象的 init方法之前 ，在postProcessBeforeInitialization方法中可以处理bean
 * (2) 在调用bean 对象的 init方法之后
 */
public class MyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (beanName.equals("userServiceBetter")){
            System.out.println("MyBeanPostProcessor~~~~~~~~~~~~~~~before,"+beanName);
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (beanName.equals("userServiceBetter")){
            System.out.println("MyBeanPostProcessor~~~~~~~~~~~~~~~after,"+beanName);
        }
        return bean;
    }
}
